package com.wenson.behavior.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: Shop
 * @Author: luowangcheng
 * @Date: 2024/6/16 16:35
 * @Description:
 */
public class Shop {
    private String product;
    private List<Buyer> buyers;//预定清单

    //初始商店无货
    public Shop() {
        this.product = "无商品";
        this.buyers = new ArrayList<>();
    }

    //注册买家到预定清单中
    public void register(Buyer buyer) {
        this.buyers.add(buyer);
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
        notifyBuyers();//到货后通知买家
    }

    public void notifyBuyers(){
        buyers.forEach(buyer -> buyer.inform(product));
    }
}
